<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Places search box</title>
    <style text="text/css">
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }

      #map-canvas, #map_canvas {
        height: 100%;
      }

      @media print {
        html, body {
          height: auto;
        }

        #map-canvas, #map_canvas {
          height: 650px;
        }
      }

      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
    <script>
function initialize() {

  var map = new google.maps.Map(document.getElementById('map-canvas'), {
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var mmarker = new google.maps.Marker({
      map: map,
      title: "title",
      position: new google.maps.LatLng(-33.8902, 151.1759)
    });

  var infowindow = new google.maps.InfoWindow({
    content: "loading..."
  });

  var defaultBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(-31.934973575952135, 115.76723098754883),
      new google.maps.LatLng(-32.009531590538174, 115.94541549682617));
  map.fitBounds(defaultBounds);

  var input = /** @type {HTMLInputElement} */(document.getElementById('target'));
  var searchBox = new google.maps.places.SearchBox(input);

  google.maps.event.addListener(searchBox, 'places_changed', function() {
    var places = searchBox.getPlaces();
    var bounds = new google.maps.LatLngBounds();

    mmarker.setMap(map);
    mmarker.setTitle(places[0].name);
    mmarker.setPosition(places[0].geometry.location);
    infowindow.setContent(places[0].geometry.location.toString());
    infowindow.open(map, mmarker);

    bounds.extend(places[0].geometry.location);

    map.fitBounds(bounds);
    map.setZoom(16)
  });

  google.maps.event.addListener(map, 'bounds_changed', function() {
    var bounds = map.getBounds();
    searchBox.setBounds(bounds);
  });

  google.maps.event.addListener(map, "click", function(event){
    infowindow.setContent(event.latLng.toString());
    mmarker.setPosition(event.latLng);
    infowindow.open(map, mmarker);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
    <style>
      #target {
        width: 345px;
      }
    </style>
  </head>
  <body>
    <div id="panel">
      <input id="target" type="text" placeholder="Search Box">
    </div>
    <div id="map-canvas"></div>
  </body>
</html>
